package com.nsl.my_youlai.bbu_return.convert.enums;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.nsl.my_youlai.bbu_return.enums.GenerationTypeEnum;
import com.nsl.my_youlai.common.base.IBaseEnum;
import com.nsl.my_youlai.mystar.enums.NslEnumBaseI;
import lombok.Data;

@Data
public class TypeEnumCovert<T extends Enum<T> & NslEnumBaseI> implements Converter<T> {

    private Class<T> tClass;
    @Override
    public Class<T> supportJavaTypeKey() {
        return tClass;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    TypeEnumCovert(){
        super();
    }

    TypeEnumCovert(Class<T> tClass){
        super();
        this.tClass=tClass;
    }

    @Override
    public T convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {

        return NslEnumBaseI.getEnumByLabel(cellData.getStringValue(),tClass);


    }


    //导出时转换
    @Override
    public WriteCellData<T> convertToExcelData(T value, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) {

        WriteCellData<T> writeCellData=new WriteCellData<>(CellDataTypeEnum.STRING,value.getLabel());
        return writeCellData;
    }
}
